//
//  MYGCommunityTopicCell.swift
//  MYGrow
//
//  Created by lance on 2024/3/3.
//

import UIKit

class MYGCommunityTopicCell: UICollectionViewCell {
    // MARK: - Property
    var model: MYGCommunityTopicModel? {
        didSet {
            guard let model = model else { return }
            label.text = "#\(model.topicName)"
        }
    }
    // MARK: - init
    override init(frame: CGRect) {
        super.init(frame: frame)
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UI
    private func configUI() {
        contentView.addSubview(label)
        label.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
        setNeedsLayout()
        layoutIfNeeded()
        let size = self.contentView.systemLayoutSizeFitting(layoutAttributes.size)
        var cellFrame = layoutAttributes.frame
        cellFrame.size.width = size.width
        layoutAttributes.frame = cellFrame
        return layoutAttributes
    }
    
    // MARK: - lazy load
    private lazy var label: UILabel = {
        let label = UILabel()
        label.textColor = .rgba(69, 131, 250)
        label.font = .regular(15)
        return label
    }()
}
